{% load static %}
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="renderer" content="webkit">
<title>字段管理</title>
<link rel="stylesheet" href="{% static '/public/css/ui.css' %}">
<link rel="stylesheet" href="{% static '/public/admin/css/layout.css' %}">
<script src="{% static 'public/js/jquery.js' %}"></script>
<script src="{% static 'public/js/ui.js' %}"></script>
</head>

<body>
	<div class="position">当前位置：系统管理 > <a href="{% url 'manager:configgroup_index' %}">设置分组</a> > <a href="{% url 'manager:configgroupfield_index' gid %}">字段管理</a></div>
		<div class="border">
			<!---->
			<a href="{% url 'manager:configgroupfield_add' gid %}" class="ui-btn ui-btn-info ui-mr-sm">添加字段</a>
			<form method="post" class="ui-form">
			<div class="ui-table-wrap">
			<table class="ui-table ui-table-border ui-table-hover ui-table-striped ui-mb ui-mt">
				<thead class="ui-thead-gray">
					<tr>
						<th width="80">排序</th>
						<th width="80">字段ID</th>
						<th>字段名称</th>
						<th width="120">Key</th>
						<th width="120">类型</th>
						<th width="80">状态</th>
						<th width="120">操作</th>
					</tr>
				</thead>
				<tbody>
            {% for item in data_items %}
            <tr>
                <td><input type="hidden" name="mid[]" value="{{item.id}}"><input type="text" class="ui-form-ip" name="ordnum[]" id="ordnum_{{item.id}}" value="{{item.ordnum}}" data-rule="required;int;"></td>
                <td>{{item.id}}</td>
                <td class="ui-text-left">{{item.ctitle}}</td>
                <td>{{item.ckey}}</td>
                <td>{% if item.ctype == 1 %}普通文本{% elif item.ctype == 2 %}普通文本-密码{% elif item.ctype == 4 %}普通文本-上传{% elif item.ctype == 5 %}多行文本框{% elif item.ctype == 6 %}单选按钮{% elif item.ctype == 7 %}复选框{% elif item.ctype == 8 %}下拉菜单{% elif item.ctype == 9 %}间隔标题{% endif %}</td>
                <td><label class="ui-switch ui-switch-info"><input type="checkbox" {% if item.islock == 1 %} checked{% endif %} data-url="{% url 'manager:configgroupfield_switchs' item.id %}"><span class="ui-switch-checkbox ui-switch-text"></span></label></td>
                <td><a href="{% url 'manager:configgroupfield_edit' item.id %}"><span class="ui-icon-edit"></span> 编辑</a>　<a href="javascript:;" class="del" data-url="{% url 'manager:configgroupfield_del' item.id %}"><span class="ui-icon-delete"></span> 删除</a></td>
            </tr>
            {% endfor %}
            </tbody>
        </table>
        </div>
        {% csrf_token %}
        <button type="submit" class="ui-btn ui-btn-yellow">保存排序</button>
        </form>
        <!---->
    </div>

<script>
$(function()
{
    const csrftoken = document.querySelector('[name=csrfmiddlewaretoken]').value;
    $('.ui-switch input[type=checkbox]').on('click',function()
	{
		var url=$(this).attr("data-url");
		var result=($(this).is(':checked'))?1:0;
		$.ajax(
		{
			url:url,
			type:"post",
			dataType:'json',
            headers: {'X-CSRFToken': csrftoken},
            mode: 'same-origin',
			data:"islock="+result,
			error:function(e){alert(e.responseText);},
			success:function(d)
			{
				if(d.state=='success')
				{
					wmcms.success(d.msg);
				}
				else
				{
					wmcms.error(d.msg);
				}
			}
		});
	});
	$(".add-iframe").click(function()
	{
		var url=$(this).attr("data-url");
		$.dialogbox(
		{
			'title':"添加分组",
			'text':url,
			'width':'500px',
			'height':'320px',
			'type':3,
			'oktheme':'ui-btn-info',
			'ok':function(e)
			{
				e.iframe().contents().find("#wmcms-submit").click();
			}
		});
	});
	$(".edit-iframe").click(function()
	{
		var url=$(this).attr("data-url");
		$.dialogbox(
		{
			'title':"编辑分组",
			'text':url,
			'width':'500px',
			'height':'320px',
			'type':3,
			'oktheme':'ui-btn-info',
			'ok':function(e)
			{
				e.iframe().contents().find("#wmcms-submit").click();
			}
		});
	});
	$(".ui-form").form(
	{
		type:2,
		result:function(form)
		{
			$.ajax(
			{
                type:'post',
                cache:false,
                dataType:'json',
                url:'{% url "manager:configgroupfield_index" gid %}',
                data:$(form).serialize(),
                error:function(e){alert(e.responseText);},
                success:function(d)
                {
                    if(d.state=='success')
                    {
                        wmcms.success(d.msg);
                        setTimeout(function(){location.href='{% url "manager:configgroupfield_index" gid %}';},1500);
                    }
                    else
                    {
                        wmcms.error(d.msg);
                    }
                }
            });
		}
	});
    $(".del").click(function()
	{
		var url=$(this).attr("data-url");
		$.dialog(
		{
			'title':"操作提示",
			'text':"确定要删除？不可恢复！",
			'oktheme':'ui-btn-info',
			'ok':function(e)
			{
				$.ajax(
				{
                    url:url,
					type:'post',
					dataType:'json',
					headers: {'X-CSRFToken': csrftoken},
                    mode: 'same-origin',
					error:function(e){alert(e.responseText);},
                    success:function(d)
                    {
                        e.close();
                        if(d.state=='success')
                        {
                            wmcms.success(d.msg);
                            setTimeout(function(){location.href='{% url "manager:configgroupfield_index" gid %}';},1000);
                        }
                        else
                        {
                            wmcms.error(d.msg);
                        }
                    }
                });
			}
		});
    });
})
</script>
</body>
</html>